from sklearn.datasets import load_iris
import numpy as np
from sklearn.linear_model import LogisticRegression

iris = load_iris()
print(list(iris.keys()))
print(iris.DESCR)
print(iris.feature_names)

X = iris.data[:, 3:]
print(X)
print(iris.target)

# y = (iris.target == 2).astype(np.int32)
# print(y)

# binary_classifier = LogisticRegression(solver='sag', max_iter=1000)

y = iris.target
# 多个二分类解决多分类问题
# multi_classifier = LogisticRegression(solver='sag', max_iter=1000, multi_class='ovr')
# softmax多分类
multi_classifier = LogisticRegression(solver='sag', max_iter=1000, multi_class='multinomial').fit(X)
multi_classifier.fit(X, y)

X_new = np.linspace(0, 3, 1000).reshape(-1, 1)
print(X_new)

y_prob = multi_classifier.predict_proba(X_new)
print(y_prob)

y_predict = multi_classifier.predict(X_new)
print(y_predict)